import excel2img
import os
import argparse

def export_single_image(excel_file, output_dir, cell_range):
    try:
        print("正在导出图片...")
        os.makedirs(output_dir, exist_ok=True)
        
        output_path = os.path.join(output_dir, args.file+".png")
        print("output_path:",output_path)
        excel2img.export_img(excel_file, output_path, None, cell_range)
        print(f"✓ 图片已保存到: {output_path}")
        
    except Exception as e:
        print(f"✗ 导出失败: {e}")

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Excel转图片')
    parser.add_argument('-p', '--path', required=True, help='根目录路径')
    parser.add_argument('-f', '--file', required=True, help='Excel文件名')
    parser.add_argument('-r', '--range', required=True, help='截图范围')
    
    args = parser.parse_args()
    
    excel_file = os.path.join(args.path, "out/excel", args.file+'.xlsx')
    output_dir = os.path.join(args.path, "out/img")
    print("excel_file:",excel_file)
    print("output_dir:",output_dir)
    export_single_image(excel_file, output_dir, args.range)